<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>车辆管理系统</title>
</head>
<body>
<h1>车辆管理系统</h1>
<button onclick="addVehicle()">添加车辆</button>

<script>
    // 示例：添加车辆的请求
    function addVehicle() {
        const vehicleData = {
            brand: "丰田",
            model: "卡罗拉",
            year: 2022
        };

        fetch('/v1/vehicle/add', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(vehicleData)
        })
            .then(response => response.json())
            .then(data => {
                if (data.state === 1002) { // NOT_LOGIN 状态码
                    alert("用户未登录，即将跳转到登录页面");
                    window.location.href = '/login.html'; // 跳转到登录页面
                } else {
                    alert("车辆添加成功");
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    }
</script>
</body>
</html>
